/*
 * SoundApplication.cpp
 *
 *  Created on: 2016年4月6日
 *      Author: terry
 */

#include "SoundApplication.h"
#include "Socket.h"
#include "CLog.h"
#include "Path.h"
#include "CRtpSound.h"

#ifdef ANDROID
#include "jni/NativeAudioDevice.h"
#else
#include "sdl/CAudioDevice.h"
#endif //

typedef comn::Singleton< SoundApplication >		SoundApplicationSingleton;


SoundApplication& SoundApplication::instance()
{
	return SoundApplicationSingleton::instance();
}

SoundApplication::SoundApplication()
{

}

SoundApplication::~SoundApplication()
{
	quit();
}


int SoundApplication::init()
{
#ifdef WIN32
	CLog::setLogger(CLog::DEBUGWINDOW);
#endif //

	CLog::setLogger(CLog::COUT);

	comn::Socket::startup();

#ifdef ANDROID

#else
	av::CAudioDevice::init();
#endif //


	CLog::info("SoundApplication::init\n");

	return 0;
}

void SoundApplication::quit()
{
	m_sounds.clear();

	comn::Socket::cleanup();

#ifdef ANDROID

#else
    av::CAudioDevice::quit();
#endif //
}


int SoundApplication::put(CRtpSoundPtr& session)
{
	if (!session)
	{
		return -1;
	}

	return m_sounds.put(session);
}

CRtpSoundPtr SoundApplication::get(int idx)
{
	if (idx < 0 || idx >= (int)m_sounds.capacity())
	{
		return CRtpSoundPtr();
	}
	return m_sounds.getAt(idx);
}

CRtpSoundPtr SoundApplication::remove(int idx)
{
    CRtpSoundPtr session;
	m_sounds.remove(idx, session);
	return session;
}

size_t SoundApplication::getCount()
{
    return m_sounds.size();
}

void SoundApplication::removeAll()
{
    m_sounds.clear();
}
